home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / tpcmag.arc / QUERY.PAS < prev    next >
Pascal/Delphi Source File  |  1986-05-19  |  1KB  |  43 lines

  1. Program QueryTest;
  2.   {from PC Magazine page 268, dated June 10, 1986 by Michael Johns
  3.    of Nampa, Indiana.  Function operates a menu selection system
  4.    using the < and > keys to position the cursor on the menu.  To use
  5.    the UP and DOWN arrow keys, two read calls will be needed because of
  6.    the extended key codes used.
  7.   }
  8. var   choice : integer;
  9.  
  10. function Query (num, row, col, choice :integer): integer;
  11. var  input : char;
  12. begin
  13.   Gotoxy (col, row + choice - 1);
  14.   write ('*');
  15.   repeat
  16.     repeat read (kbd,input);
  17.     until ord (input) in [44,46,60,62,13];
  18.     gotoxy (col, row + choice - 1);
  19.     write(' ');
  20.     if ord(input) in [44,60] then
  21.         choice := choice - 1
  22.     else if ord(input) in [46,62] then
  23.         choice :=  choice + 1;
  24.     choice := 1 + (choice + num - 1) mod num;
  25.     gotoxy(col,row+choice-1);
  26.     write('*');
  27.   until ord(input) = 13;
  28.   query := choice;
  29. end; { function Query (num, row, col, choice :integer) }
  30.  
  31. BEGIN
  32.   Clrscr;
  33.   writeln('Menu (use <, >, and Enter)');
  34.   writeln;
  35.   writeln('  1. Choice 1');
  36.   writeln('  2. Choice 2');
  37.   writeln('  3. Choice 3');
  38.   writeln('  4. Choice 4');
  39.   choice := query (4,3,1,3);
  40.   gotoxy(1,8);
  41.   writeln('Choice is ',choice);
  42. END.
  43.